import os
from config import phone
from datetime import datetime
from shutil import copyfile

def capture_screen(filename="screenshot.png", directory="."):
    """
    use adb tools

    :param filename:
    :param directory:
    :return:
    """
    if phone == 'iphone':
        print(os.path.join(directory, filename))
        os.system('idevicescreenshot {0}'.format(os.path.join(directory, filename)))
    else:
        os.system("adb shell screencap -p /sdcard/{0}".format(filename))
        os.system("adb pull /sdcard/{0} {1}".format(filename, os.path.join(directory, filename)))
def save_screen(imgs = [], filename="screenshot.png", directory="../screenshots", disDir = "../training"):
    """
    Save screen for further test
    :param filename:
    :param directory:
    :return:
    """
    absDir = os.path.dirname(os.path.realpath(__file__))
    disDir = os.path.abspath(os.path.join(absDir, disDir))
    print('图片存入:', disDir)
    for i, img in enumerate(imgs):
        img.save(os.path.join(disDir, datetime.now()
                          .strftime("%y%m%d_%H%M%S_s{0}".format(i)).join(os.path.splitext(filename))))
    copyfile(os.path.join(directory, filename),
             os.path.join(directory, datetime.now().strftime("%y%m%d_%H%M%S").join(os.path.splitext(filename))))
# save_screen()